package main

import (
	"fmt"
	"io"
	"os"
	"reflect"
)

func basics()  {
	// reflect包定义了两种类型，Type, Value

	t := reflect.TypeOf(3)
	fmt.Println(t.String())
	fmt.Println(t)

	var w io.Writer = os.Stdout
	fmt.Println(reflect.TypeOf(w))

	fmt.Printf("shorthand for TypeOf:%T\n", 3)

	// Value can hold value of any type
	v := reflect.ValueOf(3) // a reflect value
	fmt.Println(v) //3
	fmt.Printf("%v\n", v) // 3
	fmt.Println(v.String()) // <int value>

	//在Value上调用Type会返回reflect.Type
	tt := v.Type()
	fmt.Println("type from v.Type:", tt)

	interfaceFromReflectValue := v.Interface()//an interface{}
	fmt.Println("convert interface to int:%d", interfaceFromReflectValue.(int))
}

func main() {
	basics()
}
